home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
pt20pc.zip
/
WINDTEXT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-04
|
19KB
|
775 lines
#include "pt.h"
#include "string.h"
/* XTAG:maxLineLength */
static int maxLineLength = 1;
void pascal
/* XTAG:drawWindow */
drawWindow(w)
register struct window *w;
{
extern unsigned char border1[], border2[], border3[], border4[];
extern struct window *activeWindow;
extern int debug;
register unsigned char *border;
fillWindow(w, 1);
/* put in the banner first so the box will not overwrite it */
banner(w);
if( w != activeWindow )
border = &border1[0];
else
border = &border2[0];
drawBorder(border, w->row1, w->col1, w->row2, w->col2,
w->borderColor, 0);
updateScreen(w->row1, w->row2);
}
void pascal
/* XTAG:drawBorder */
drawBorder(border, row1, col1, row2, col2, borderColor, bottomLineOnly)
unsigned char *border;
int row1, row2, col1, col2, borderColor, bottomLineOnly;
{
register int i;
if( !bottomLineOnly ) {
/* put in the top two corners */
displayChar(row1, col1, 254, borderColor);
displayChar(row1, col2, 254, borderColor);
/* put in the top border of the box */
displayChar(row1, col1, border[0], borderColor);
for(i = col1+1; i < col2; i++)
displayChar(row1, i, border[1], borderColor);
displayChar(row1, col2, border[2], borderColor);
/* put in the sides of the box */
for(i = row1+1; i < row2; i++) {
displayChar(i, col1, border[3], borderColor);
displayChar(i, col2, border[4], borderColor);
}
}
/* put in the bottom two corners */
displayChar(row2, col1, 254, borderColor);
displayChar(row2, col2, 254, borderColor);
/* put in the bottom row of the box */
displayChar(row2, col1, border[5], borderColor);
for(i = col1+1; i < col2; i++)
displayChar(row2, i, border[6], borderColor);
displayChar(row2, col2, border[7], borderColor);
}
void pascal
/* XTAG:banner */
banner(w)
register struct window *w;
{
extern unsigned char border1[8];
extern unsigned char textBuffer[];
extern int overType;
extern struct openFile *files;
extern int pathNames;
extern struct window *activeWindow;
extern unsigned int piecesLeft;
extern unsigned int bytesLeft;
extern int debug;
register int i;
int row1, row2, col, len;
int stopBlink, color;
unsigned char fillChar;
long lp;
struct openFile *ff;
/* see if we need a scroll bar on the bottom border */
len = w->col2 - w->col1 - 1;
if( len < maxLineLength || w->indent > 0 ) {
/* fill in the highlighted, bottom side position bar */
/* we are reusing the row1, row2 variables */
/* they really represent columns here */
row1 = 1 + (w->col1) + (len*w->indent) / maxLineLength;
row2 = 1 + (w->col1) + (len*(len+w->indent)) / maxLineLength;
if( row2 >= w->col2 )
row2 = w->col2 - 1;
if( row1 > row2 )
row1 = row2;
for(i = row1; i <= row2; i++)
displayChar(w->row2, i, 196, w->elevColor);
}
/* does this window have a banner at all? */
if( (w->state & 0x8) == 0x8 )
return;
if( w != activeWindow )
fillChar = ' ';
else
fillChar = 205;
if( w->fileId == -1 ) {
lp = 0;
w->numTopline = 0;
w->numBotline = 1;
} else {
ff = &files[w->fileId];
lp = ff->fileSize;
}
i = 0;
if( w->numTopline >= w->numBotline )
i = 1;
col = (pathNames ? 0 : w->nameOffset);
stopBlink = ((bytesLeft < SPACELOW) && (piecesLeft == 0) ? 5 : 0);
sprintf(textBuffer,
"%c%s \256%s\257%s%s%s%s lines %d-%d columns %d-%d",
fillChar,
(stopBlink == 5 ? "SAVE" : ""),
&((files[w->fileId].origName)[col]),
/* three state flags */
(files[w->fileId].isChanged ? "*" : ""),
(overType ? " OverType" : ""),
(ff->readOnly ? " ReadOnly" : ""),
( ( (w->state & 0x2) == 0x2) ? " UNIX" : ""),
/* line and column numbers */
w->numTopline - i, w->numBotline - 1,
w->indent + 1, (w->col2 - w->col1 + w->indent - 1));
len = strlen(textBuffer);
row1 = w->row1;
col = w->col1 + 1;
for(i = 0; textBuffer[i] != '\0'; i++) {
if( i < stopBlink && i > 0 )
color = 0xF8;
else
color = w->bannerColor;
displayChar(row1, col++, textBuffer[i], color);
if( col >= w->col2 )
break;
}
/* fill top row with reverse video spaces */
while( col < w->col2 )
displayChar(row1, col++, fillChar, w->bannerColor);
/* fill in the highlighted, left side position bar */
row1 = 1 + (w->row1) +
(int)(((long)(w->row2-w->row1-1) * w->posTopline) / (lp+1L));
row2 = 1 + (w->row1) +
(int)(((long)(w->row2-w->row1-1) * w->posBotline) / (lp+1L));
for(i = row1; i <= row2; i++) {
displayChar(i, w->col1, 179, w->elevColor);
}
}
void pascal
/* XTAG:fillWindow */
fillWindow(w, doUpdates)
register struct window *w;
{
extern unsigned char *screenMap;
extern unsigned char *screenChars;
extern unsigned char scrMapReset;
extern unsigned int dispMemory;
extern int debug;
extern int scrRows, scrCols;
long cp;
int n;
int row1, row2, col1, col2;
unsigned char *sChars, *sMap, *sMapLimit;
unsigned char color;
maxLineLength = 1; /* reset this count */
/* get the corners of the inside of the window */
row1 = w->row1 + 1;
col1 = w->col1 + 1 ;
row2 = w->row2 - 1;
col2 = w->col2 - 1;
/* fill the rows one at a time */
cp = w->posTopline;
n = w->numTopline;
while( row1 <= row2 ) {
cp = fillLine(w, cp, row1, col1, col2);
if( doUpdates )
updateScreen(row1, row1);
if( cp == -1 )
break;
n++;
row1++;
}
if( cp == -1 )
cp = fileSize(w->fileId);
w->posBotline = cp;
w->numBotline = n;
color = w->textColor;
while( ++row1 <= row2 ) {
sMap = screenMap + scrCols*row1 + col1;
sMapLimit = screenMap + scrCols*row1 + col2;
sChars = screenChars + (scrCols<<1)*row1 + (col1<<1);
while( sMap <= sMapLimit ) {
if( *sMap != 0 ) {
*sMap = scrMapReset;
*sChars++ = ' ';
*sChars++ = color;
} else
sChars += 2;
++sMap;
}
if( doUpdates )
updateScreen(row1, row1);
}
}
extern void repword(unsigned int, unsigned char *, int);
long pascal
/* XTAG:fillLine */
fillLine(w, cp, row, col1, col2)
struct window *w;
long cp;
int row, col1, col2;
{
extern struct window *selWindow;
extern struct window *windowList;
extern long selBegin, selEnd;
extern unsigned char msgBuffer[];
extern int tabWidth;
extern unsigned char *screenMap;
extern unsigned char *screenChars;
extern unsigned char scrMapReset;
extern int debug;
extern int invisibleText;
extern int scrCols;
extern struct SREGS segRegs;
extern unsigned char charTable[];
unsigned char ch, nullChar, color;
unsigned int buf;
register unsigned char *sMap;
register unsigned char *sChars;
unsigned char *sMapLimit;
unsigned char far *firstByte;
unsigned char far *lastByte;
int insertIndex;
long cp2;
int tabStop, indent, col;
int iBuffer, eofFlag;
unsigned char textAttr, selAttr;
eofFlag = 0;
insertIndex = -1;
/* for top window optimization */
buf = (unsigned int)' ' + ( ((unsigned int)w->textColor) << 8 );
/* set up the color codes */
textAttr = w->textColor;
selAttr = w->selColor;
/* get the text in the line */
cp2 = cp;
firstByte = (unsigned char far *)1;
lastByte = (unsigned char far *)0;
/* set up for the loop */
iBuffer = 0;
col = 0; /* count columns starting at 0 */
indent = w->indent;
sMap = screenMap + scrCols*row + col1;
sMapLimit = screenMap + scrCols*row + col2;
sChars = screenChars + (scrCols<<1)*row + (col1<<1);
while( sMap <= sMapLimit ) {
/* is char at file position cp2 part of the selection? */
if( w == selWindow && selBegin <= cp2 && cp2 <= selEnd )
color = selAttr;
else
color = textAttr;
if( firstByte > lastByte ) {
if(getSpan(w->fileId, cp2, &firstByte, &lastByte,0)){
nullChar = 0; /* end of file */
eofFlag = 1;
firstByte = &nullChar;
lastByte = firstByte;
}
}
#ifdef ANASAZI
if( anasazi
&& insertIndex != -1
&& (ch = insertString[insertIndex]) != '\0' )
++insertIndex;
else
#endif
ch = *firstByte++;
++cp2;
switch( charTable[ch] ) {
case 1: /* newline -- end of line */
if( col >= indent ) {
if( *sMap != 0 ) {